<?php

$oTpl = &App::getTemplate();

$oReq = &App::getRequest();

$oDb = &Database::get();

$oLang = &App::getLanguage();

App::loadClass('Validator');

$iId = $oReq->get('id');

if ( $oReq->get('save') )
{
	$aPost = $oReq->getArray('val');

	$aQuery = array
	(
		'languageid' => $iId,
		'varid' => $oLang->getOptionVarId($aPost['option']),
		'varname' => $aPost['option'],
		'text' => $aPost['text'],
		'product' => 'konsort',
		'time' => time(),
		'default' => $aPost['text'],
	);

	$oDb->insert(App::getT('language_options'), $aQuery);

	$sTempFormat = App::format('Mod_Language.new_option_added');

	Cache::subStrRemove('option_');

	App::gotoUrl('admin.language.add-option', array('id' => $iId), $sTempFormat, false);
}

$aFields = array
(
	'val[text]'   => array('title' => App::format('Mod_Language.text'), 'def' => 'required'),
);
$oValidator = &new Validator($aFields, array());

$aOptions = $oDb->getRows("SELECT varname, languagevar FROM ". App::getT('product_options') ."");

$oTpl->assignSrc('sValMess', $oValidator->makeJsMess());
$oTpl->assignSrc('sValJs', $oValidator->makeJS());
$oTpl->assign(array
(
	'aOptions' => $aOptions,
	'aItem' => (isset($aPost) ? $aPost : ''),
	'iId' => $iId,
	'aLanguages' => $oLang->getLanguages(),
));

?>